package org.springsecuritylearn.repository.domain;


import lombok.Data;
import lombok.Getter;
import lombok.Setter;

import javax.persistence.*;
import java.util.List;

/**
 * 书的信息类
 */
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
@NamedEntityGraph(name = "Book.fetch.category.and.author",attributeNodes =
        {
                @NamedAttributeNode("category"),
                @NamedAttributeNode("bookAuthorList")
        })//使所有查询都是关联查询
public class Book  extends CreatAndUpdateTime{


    @Getter
    @Setter
    @Id
    @GeneratedValue
    private Long id;

    @Getter
    @Setter
    @Basic
    private String name;

    @Getter
    @Setter
    //乐观锁 ，版本号
    @Version
    private  int  version;

    /**
     * 对应的书籍门类
     */
    @Getter
    @Setter
    @ManyToOne
    private Category category;

    @Getter
    @Setter
    @OneToMany(mappedBy = "book")
    private List<BookAuthor> bookAuthorList;


    @Override
    public String toString() {
        return "Book{" +
                "id=" + id +
                ", name='" + name + '\'' +
                '}';
    }
}
